/*
 * @Author: duanguang
 * @Date: 2022-03-03 09:28:10
 * @LastEditTime: 2022-03-03 18:59:13
 * @LastEditors: duanguang
 * @Description: 
 * @FilePath: /legions-server/app/model/branch_merge_request.ts
 * 「扫去窗上的尘埃，才可以看到窗外的美景。」
 */
import { Model, Document, Schema } from '.';
import { Application } from 'egg';

/** 分支合并申请请求实体 */
export class BranchMergeRequest {
    /** 项目名称 */
    repository_name: string = '';

    project_id:string=''

    /** 目标分支名称 */
    target_branch: string = '';

    /** 来源分支名称 */
    source_branch: string = '';

    /** gitlab 合并请求iid */
    merge_request_iid: number = -1;
    /** 合并请求标题 */
    merge_title: string = ''
    
    /** 仓库地址 */
    repository_https: string = ''
        
    /** 合并请求描述信息 */
    merge_description: string = ''
    /** 指派review人员id */
    reviewer_members_id: string = '';
     /** 指派review人员 gitlab id */
    reviewer_members_gitlab_id: string = '';
    /** 指派review人员 */
    reviewer_members:string=''
    /** 审批人 */
    assign_members: string = ''
    
    /** 审批人id */
    assign_members_id: string = ''
    assign_members_gitlab_id: string = ''
    
    /** 审查状态 
     * 
     * 0表示待审核
     * 
     * 1表示审核通过
     * 
     * 2 驳回
     */
    audit_status:string =''
    
    /** 创建人id */
    creator_id: string = ''
    
    /** 创建人 */
    creator: string = ''

     /** gitlab 仓库项目id */
    gitlab_project_id: string = ''
    
    /** 项目分组信息 */
    gitlab_project_group:string =''
    
    /** 创建时间 */
    create_time: number = new Date().getTime();

    
    /** 修改时间 */
    update_time: number = new Date().getTime();
}

export interface IBranchMergeRequestModel extends Document, BranchMergeRequest {}

export default function BranchMergeRequestModel(
    app: Application,
): Model<IBranchMergeRequestModel> {
    const mongoose = app.mongoose;
    const Schema = mongoose.Schema;
    const mergeRequestSchema: Schema = new Schema({
        repository_name: { type: String },
        project_id: { type: String },
        target_branch: { type: String },
        source_branch: { type: String },
        merge_request_iid: { type: Number },
        merge_title: { type: String },
        repository_https: { type: String },
        merge_description: { type: String },
        assign_members: { type: String },
        assign_members_id: { type: String },
        assign_members_gitlab_id: { type: String },
        reviewer_members_id: { type: String },
        reviewer_members_gitlab_id: { type: String },
        reviewer_members: { type: String },
        audit_status: { type: String },
        creator_id: { type: String },
        creator: { type: String },
        gitlab_project_id: { type: String },
        gitlab_project_group: { type: String },
        create_time: { type: Number },
        update_time: { type: Number },
    }, {
        timestamps: { updatedAt: 'update_time', createdAt: 'create_time' },
    });
    return mongoose.model<IBranchMergeRequestModel>(
        'branch_merge_request',
        mergeRequestSchema,
    );
}
